<?php

/**
 * 
 * 生活服务模型模型
 */
class ServiceModel extends Model {

    public function fabu($param) {
        //参数过滤
        M()->startTrans();
        //@todo 模版付费口积分
        $theme_id = format_int($param['theme_id']);
        if (!$theme_id) {
            return reStatus(false, '请选择合适的名片模版');
        }
        $theme = M('CardTheme')->find($theme_id);
        if ($theme['score'] > 0) {
            //@todo 扣除积分
            $decScore = D('UserAccount')->chargeUserAccount(session(uid), -$theme['score'], 'FABU_DAZHE', '发布生活服务模版扣除金币' . $theme['score']);
            if ($decScore['status'] == false) {
                return reStatus(false, $decScore['msg']);
            }
        }

        $service = array(
            'user_id'     => session('uid'),
            'name'        => t($param['name']),
            'sex'         => t($param['sex']),
            'age'         => (int) ($param['age']),
            'location'    => t($param['location']),
            'phone'       => format_int($param['phone']),
            'pic_url'     => t($param['pic_url']),
            'address'     => t($param['address']),
            'cat_ids'     => t($param['cat_ids']),
            'fee'         => t($param['fee']),
            'theme_id'    => $theme_id,
            'info'        => h($param['info']),
            'great_count' => 0,
            'status'      => 1,
            'create_time' => time(),
        );
        $serviceID    = $this->add($service);
        if ($serviceID) {
            M()->commit();
            return reStatus(true, '', $serviceID);
        } else {
            M()->rollback();
            return reStatus(false, '');
        }
    }

}

?>
